<template>
    <div class="escorts">
        <van-nav-bar title="院内陪护" left-text="返回" left-arrow @click-left="onClickLeft" class="nav" />
        <img src="/public/escort.jpg" class="top_img">
        <div class="escort_detail" v-for="(item, i) in serviceData" :key="i"
            @click="handleConClick(item.service_item, item.service_price)">
            <h3 class="escort_item">{{ item.service_item }}</h3>
            <span class="escort_dec">{{ item.service_introduction }}</span>
            <div class="escort_right">
                <span class="escort_price">￥{{ item.service_price }}</span>元/天
            </div>
        </div>
    </div>
</template>
<script setup>
import { ref, reactive, onMounted } from 'vue';
import http from '../http';
import { useRouter } from 'vue-router';
const router = useRouter()
let serviceData = ref('')
const onClickLeft = () => history.back();
onMounted(() => {
    http.get('/patient/inhospital_services/').then(res => {
        console.log("院内陪诊信息", res.data.service);
        serviceData.value = res.data.service;
        console.log('<<<', serviceData.value)
    }).catch(error => {
        console.log(error)
    })
})
const serviceItemToRouteMap = {
    "专业陪护": "/professional",
    "12小时陪护": "/daycompany",
};

const handleConClick = (serviceItem, servicePrice) => {
    const routePath = serviceItemToRouteMap[serviceItem];
    if (routePath) {
        router.push({
            path: routePath,
            query: {
                serviceItem: serviceItem,
                servicePrice: servicePrice
            }
        });
    } else {
        console.log(`未配置对应路由的服务项目: ${serviceItem}`);
    }
};

</script>
<style scoped>
.escorts {
    position: absolute;
    height: 100%;
    background-color: rgb(245, 245, 245);
}

.top_img {
    width: 100%;
    height: 200px;
}

.escort_detail {
    position: relative;
    background-color: #fff;
    margin: 5% 5% 0;
    width: 90%;
    height: 80px;
    border-radius: 10px;
    font-size: 12px;
}

.escort_item {
    position: absolute;
    left: 10%;
    top: 0;
    font-weight: 700;
}

.escort_right {
    position: absolute;
    right: 5%;
    top: 10%;
    font-weight: 700;
    font-size: 16px;
    color: rgb(247, 114, 19);
}

.escort_dec {
    position: absolute;
    left: 10%;
    top: 50%;
}

.escort_price {
    font-weight: 900;
    font-size: 18px;
}
</style>